package com.weixing.mall.provider.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weixing.mall.core.support.auth.SysAuth;
import com.weixing.mall.provider.mapper.AgreementMapper;
import com.weixing.mall.provider.model.domain.Agreement;
import com.weixing.mall.provider.service.IAgreementService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 系统协议，主要包括申请成为代理商、申请成为会员，以及积分兑换等。 服务实现类
 * </p>
 *
 * @author Small
 * @since 2020-05-28
 */
@Service
public class AgreementServiceImpl extends ServiceImpl<AgreementMapper, Agreement> implements IAgreementService {
    @Override
    public void updateByCode(String code, String content, SysAuth auth) {
        update(new LambdaUpdateWrapper<Agreement>().eq(Agreement::getCode,code).set(Agreement::getContent,content).set(Agreement::getUpdatedBy,auth.getUid()));
    }

    @Override
    public String getByCode(String code) {
        Agreement agreement = getOne(new LambdaQueryWrapper<Agreement>().eq(Agreement::getCode,code));
        return ObjectUtil.isNotEmpty(agreement)?agreement.getContent():"";
    }
}
